package restless.aimovement.astar.analyzers {
	
	import flash.geom.Point;
	import restless.aimovement.astar.Analyzer;
	import restless.aimovement.astar.interfaces.IMap;
	import restless.aimovement.astar.interfaces.IPositionTile;
	
	/**
	 * @author Jeroen
	 */
	
	 public class AvoiderAnalyzer extends Analyzer 	{
		
		private var _avoid:Point;
		private var _distance:Number;
		
		public function AvoiderAnalyzer(toAvoid:Point, distance:Number)	{
			_avoid = toAvoid;
			_distance = distance;
			super();
		}
		
		override public function analyzeTile(tile: *):Boolean {
			var pos:Point = (tile as IPositionTile).position;
			return (Math.abs(pos.x - _avoid.x) + Math.abs(pos.y - _avoid.y) > _distance);
		}
		
		override protected function analyze(mainTile:*, allNeighbours:Array, neighboursLeft:Array, map:IMap) : Array {
			var newLeft:Array = new Array();
			var currentPos:Point;
			var currentDistance:Number;
			var tempTile:IPositionTile;
			for(var i:Number = 0; i< neighboursLeft.length; i++) {
				tempTile = neighboursLeft[i] as IPositionTile;
				currentPos = tempTile.position;
				currentDistance = Math.abs(_avoid.x - currentPos.x) + Math.abs(_avoid.y - currentPos.y);
				if (currentDistance > _distance) { newLeft.push(tempTile); }
			}
			return newLeft;
		} 
		
		public function get avoidPoint():Point {
			return _avoid;
		}
		
		public function set avoidPoint(toAvoid:Point):void {
			_avoid = toAvoid;
		}
		
		public function get distance():Number {
			return _distance;
		}
		
		public function set distance(distance:Number):void	{
			_distance = distance;
		}
	}
}